package cn.bopomo.dealer.base.util;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class ResultCodeDescHandler extends DefaultHandler {

	private boolean isCode = false;
	private boolean isDesc = false;
	private boolean isDescValue = false;
	private String code_value = "00";
	private String description = "";
	
	public ResultCodeDescHandler(String codeValue){
		this.code_value = codeValue;
	}
	
	
	public void characters(char[] ch, int start, int length) throws SAXException {
		// TODO Auto-generated method stub
		if(isCode){
			String value = new String(ch, start, length);
			if(value.equals(this.code_value))
				isDescValue = true;
		}
		
		if(isDesc && isDescValue)
			this.description = new String(ch, start, length);
	}

	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
		// TODO Auto-generated method stub
		if(qName.equalsIgnoreCase("code"))
			isCode = true;
		if(qName.equalsIgnoreCase("description"))
			isDesc = true;
	}


	public void endElement(String uri, String localName, String qName) throws SAXException {
		if(qName.equalsIgnoreCase("code"))
			isCode = false;
		if(qName.equalsIgnoreCase("description")){
			isDesc = false;
			isDescValue = false;
		}
	}


	public String getDescription() {
		return description;
	}

}
